home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / text / hyper / hsc_source.lha / source / hsc / hsc.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  5KB  |  195 lines

  1. /*
  2.  * hsc - HTML sucks completely
  3.  *
  4.  * Another stupid HTML-preprocessor
  5.  *
  6.  * Copyright (C) 1995,96  Thomas Aglassinger
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  *-------------------------------------------------------------------
  23.  *
  24.  * Author : Thomas Aglassinger (Tommy-Saftwörx)
  25.  * Email  : agi@giga.or.at, agi@sbox.tu-graz.ac.at
  26.  * Address: Lissagasse 12/II/9
  27.  *          8020 Graz
  28.  *          AUSTRIA
  29.  *
  30.  *-------------------------------------------------------------------
  31.  *
  32.  * hsc/hsc.c
  33.  *
  34.  * updated:  9-Sep-1996
  35.  * created:  1-Jul-1995
  36.  */
  37.  
  38. #include "hsc/global.h"
  39. #include "hscprj/project.h"
  40.  
  41. /*
  42.  * ugly includes
  43.  */
  44. #include "ugly/uargs.h"
  45. #include "ugly/prginfo.h"
  46. #include "ugly/returncd.h"
  47.  
  48. /*
  49.  * local includes
  50.  */
  51. #include "hsc/args.h"
  52. #include "hsc/callback.h"
  53. #include "hsc/output.h"
  54. #include "hsc/status.h"
  55.  
  56. #if !(defined VERSTAG)
  57. #include "hsc/hsc_rev.h"
  58. #endif
  59.  
  60. /* import AmigaOS version string from "hsc/hsc_rev.h" */
  61. #ifdef AMIGA
  62. static const char AmigaOS_version[] = VERSTAG;
  63. #endif
  64.  
  65. /* hsc-process structure that is used during
  66.  * the wohle conversion */
  67. static HSCPRC *hp = NULL;
  68.  
  69. /*
  70.  * includes_ok
  71.  *
  72.  * process include-files passed via command line
  73.  */
  74. static BOOL include_ok(HSCPRC * hp)
  75. {
  76.     BOOL ok = TRUE;
  77.  
  78.     if (incfile)
  79.     {
  80.         DLNODE *nd = dll_first(incfile);
  81.  
  82.         while (nd && ok)
  83.         {
  84.             STRPTR filename = (STRPTR) dln_data(nd);
  85.             ok = hsc_include_file(hp, filename, IH_IS_INCLUDE);
  86.             nd = dln_next(nd);
  87.         }
  88.     }
  89.     return (ok);
  90. }
  91.  
  92. /*
  93.  * cleanup: free all resources
  94.  * (called in any case)
  95.  */
  96. static VOID cleanup(VOID)
  97. {
  98. #if DEBUG
  99.     /* just because I'm curious how long cleanup lasts */
  100.     /* NOTE: obviously, it last very long */
  101.     fputs("(cleanup)\r", stderr);
  102.     fflush(stderr);
  103. #endif
  104.  
  105.     del_hscprc(hp);
  106.     cleanup_global();
  107.     cleanup_output();
  108.     cleanup_msgfile();
  109.     cleanup_hsc_args();
  110.  
  111. #if DEBUG
  112.     fputs("         \r", stderr);
  113.     fflush(stderr);
  114. #endif
  115.  
  116. }
  117.  
  118. /*
  119.  *
  120.  * main function
  121.  *
  122.  */
  123. int main(int argc, char *argv[])
  124. {
  125.     /* set program information */
  126.     set_prginfo("hsc", "Tommy-Saftwörx", VERSION, REVISION, BETA,
  127.                 "html sucks completely",
  128.                 "Freeware, type `hsc LICENSE' for details.");
  129.  
  130. #if DEBUG
  131.     /* display a memory tracking report
  132.      * at end of execution */
  133.     atexit(atexit_uglymemory);
  134. #endif
  135.  
  136.     /* install nomem-handler; this one displays a message
  137.      * and aborts the program */
  138.     ugly_nomem_handler = hsc_nomem_handler;
  139.  
  140.     /* use cleanup() as additional exit func
  141.      * (even called if out-of-memory) */
  142.     if (!atexit(cleanup))
  143.     {
  144.         /*
  145.          * main procedure
  146.          */
  147.         hp = new_hscprc();      /* alloc new hsc-process */
  148.         if (hp
  149.             && init_global()    /* init global vars */
  150.             && args_ok(hp, argc, argv)  /* process user args */
  151.             )
  152.         {
  153.             STRPTR inpfname = NULL;     /* input-filename */
  154.  
  155.             /* display programm-info if requested */
  156.             if (disp_status_version)
  157.                 fprintf_prginfo(stderr);
  158.  
  159.             if (init_msgfile(hp, msgfilename)   /* open message file */
  160.                 && init_output(hp))     /* open output file */
  161.             {
  162.                 /* init return code; later modified by message() */
  163.                 return_code = RC_OK;
  164.  
  165.                 /* evaluate input-filename; use NULL for stdin */
  166.                 inpfname = estr2str(inpfilename);
  167.                 if (!inpfname[0])
  168.                     inpfname = NULL;
  169.  
  170.                 /* init process & read preferences */
  171.                 if (init_callback(hp)   /* assign callbacks */
  172.                     && hsc_init_hscprc(hp, prefsfilename)       /* init hsc-process */
  173.                     && hsc_init_project(hp, prjfilename)        /* read project */
  174.                     && user_defines_ok(hp)      /* process user defines */
  175.                     && include_ok(hp)   /* read include files (macros) */
  176.                     && hsc_include_file(hp, inpfname,
  177.                                         IH_PARSE_END | IH_IS_SOURCE
  178.                                         | IH_UPDATE_PRJ)        /* read main file */
  179.                     )
  180.                 {
  181.                     if (write_output(hp))       /* write output file */
  182.                         hsc_project_write_file(hp->project, prjfilename);
  183.                 }
  184.             }
  185.         }
  186.     }
  187.     else
  188.     {
  189.         status_error("atexit() failed ");
  190.     }
  191.  
  192.     return (return_code);
  193. }
  194.  
  195.